﻿#ifndef CONFIG_H
#define CONFIG_H

#include <QString>
#include <QStringList>
#include <QSettings>
#include <QDir>
#include <string.h>

#define LEFTSTEP 10
#define RIGHTSTEP 10
#define SLOWRATE 100
#define FASTRATE 300

typedef struct _UI_CONF_VAR{
    char    Title[64];
    int     Start;
    int     MouseWheelStep;
    int     MouseMoveStep;
    int     WindowMax;
    int     WindowClose;
    int     WindowWidth;
    int     WindowHeight;
    int     WindowSetupWidth;
    int     WindowSetupHeight;
    int     Debug;
}UI_CONF_VAR;

typedef struct _UI_UI_VAR{
    int     MessageBoxSize;
    int     PushButtonPressTimer;
    int     PushButtonSetupSize;
    int     PushButtonSetupWidth;
    int     PushButtonSetupHeight;
    char    PushButtonSetupText[16];
    int     PushButtonExitSize;
    int     PushButtonExitWidth;
    int     PushButtonExitHeight;
    char    PushButtonExitText[16];
    int     PushButtonHaltSize;
    int     PushButtonHaltWidth;
    int     PushButtonHaltHeight;
    char    PushButtonHaltText[16];
    int     LabelPositionSize;
    int     LabelPositionWidth;
    int     LabelPositionHeight;
    char    LabelPositionText[16];
    int     PushButtonForBackMoveInSize;
    int     PushButtonForBackMoveInWidth;
    int     PushButtonForBackMoveInHeight;
    char    PushButtonForBackMoveInText[16];
    int     PushButtonForBackMoveOutSize;
    int     PushButtonForBackMoveOutWidth;
    int     PushButtonForBackMoveOutHeight;
    char    PushButtonForBackMoveOutText[16];
    int     PushButtonForBackResetSize;
    int     PushButtonForBackResetWidth;
    int     PushButtonForBackResetHeight;
    char    PushButtonForBackResetText[16];
    int     PushButtonForBackUpSize;
    int     PushButtonForBackUpWidth;
    int     PushButtonForBackUpHeight;
    char    PushButtonForBackUpText[16];
    int     PushButtonForBackDownSize;
    int     PushButtonForBackDownWidth;
    int     PushButtonForBackDownHeight;
    char    PushButtonForBackDownText[16];
    int     PushButtonPushMoveDownSize;
    int     PushButtonPushMoveDownWidth;
    int     PushButtonPushMoveDownHeight;
    char    PushButtonPushMoveDownText[16];
    int     PushButtonPushMoveUpSize;
    int     PushButtonPushMoveUpWidth;
    int     PushButtonPushMoveUpHeight;
    char    PushButtonPushMoveUpText[16];
    int     PushButtonPushMoveResetSize;
    int     PushButtonPushMoveResetWidth;
    int     PushButtonPushMoveResetHeight;
    char    PushButtonPushMoveResetText[16];
    int     LabelMoveSize;
    int     LabelMoveWidth;
    int     LabelMoveHeight;
    char    LabelMoveText[16];
    int     PushButtonLeftFastSize;
    int     PushButtonLeftFastWidth;
    int     PushButtonLeftFastHeight;
    char    PushButtonLeftFastText[16];
    int     PushButtonRightFastSize;
    int     PushButtonRightFastWidth;
    int     PushButtonRightFastHeight;
    char    PushButtonRightFastText[16];
    int     PushButtonLeftMoveSize;
    int     PushButtonLeftMoveWidth;
    int     PushButtonLeftMoveHeight;
    char    PushButtonLeftMoveText[16];
    int     PushButtonRightMoveSize;
    int     PushButtonRightMoveWidth;
    int     PushButtonRightMoveHeight;
    char    PushButtonRightMoveText[16];
}UI_UI_VAR;

typedef struct _UI_SETUP_VAR{
    char    LabelLeftTitleText[16];
    int     LabelLeftTitleSize;
    int     LabelLeftTitleWidth;
    int     LabelLeftTitleHeight;
    int     SpinBoxLeftValueSize;
    int     SpinBoxLeftValueWidth;
    int     SpinBoxLeftValueHeight;
    int     PushButtonLeftAddSize;
    int     PushButtonLeftAddWidth;
    int     PushButtonLeftAddHeight;
    int     PushButtonLeftDecSize;
    int     PushButtonLeftDecWidth;
    int     PushButtonLeftDecHeight;
    char    LabelRightTitleText[16];
    int     LabelRightTitleSize;
    int     LabelRightTitleWidth;
    int     LabelRightTitleHeight;
    int     SpinBoxRightValueSize;
    int     SpinBoxRightValueWidth;
    int     SpinBoxRightValueHeight;
    int     PushButtonRightAddSize;
    int     PushButtonRightAddWidth;
    int     PushButtonRightAddHeight;
    int     PushButtonRightDecSize;
    int     PushButtonRightDecWidth;
    int     PushButtonRightDecHeight;
    char    LabelSlowTitleText[16];
    int     LabelSlowTitleSize;
    int     LabelSlowTitleWidth;
    int     LabelSlowTitleHeight;
    int     SpinBoxSlowValueSize;
    int     SpinBoxSlowValueWidth;
    int     SpinBoxSlowValueHeight;
    int     PushButtonSlowAddSize;
    int     PushButtonSlowAddWidth;
    int     PushButtonSlowAddHeight;
    int     PushButtonSlowDecSize;
    int     PushButtonSlowDecWidth;
    int     PushButtonSlowDecHeight;
    char    LabelFastTitleText[16];
    int     LabelFastTitleSize;
    int     LabelFastTitleWidth;
    int     LabelFastTitleHeight;
    int     SpinBoxFastValueSize;
    int     SpinBoxFastValueWidth;
    int     SpinBoxFastValueHeight;
    int     PushButtonFastAddSize;
    int     PushButtonFastAddWidth;
    int     PushButtonFastAddHeight;
    int     PushButtonFastDecSize;
    int     PushButtonFastDecWidth;
    int     PushButtonFastDecHeight;
    char    PushButtonSaveText[16];
    int     PushButtonSaveSize;
    int     PushButtonSaveWidth;
    int     PushButtonSaveHeight;
    char    PushButtonCancelText[16];
    int     PushButtonCancelSize;
    int     PushButtonCancelWidth;
    int     PushButtonCancelHeight;
}UI_SETUP_VAR;

typedef struct _UI_SHELL_VAR{
    char    LabelShell1[128];
    char    LabelShell2[128];
    char    SpinBoxShell[128];
    char    PushButtonShellDisabled[128];
    char    PushButtonShell1[128];
    char    PushButtonShellHover1[128];
    char    PushButtonShellPressed1[128];
    char    PushButtonShell2[128];
    char    PushButtonShellHover2[128];
    char    PushButtonShellPressed2[128];
    char    PushButtonShell3[128];
    char    PushButtonShellPressed3[128];
}UI_SHELL_VAR;

typedef struct _UI_UIM_VAR{
    int     UsbPort;
    int     ComPort;
    int     CanTimer;
    int     CanLeftId;
    int     CanLeftOrg;
    int     CanLeftEncodeState;
    int     CanLeftOff;
    int     CanLeftRate;
    int     CanLeftStep;
    int     CanLeftSlowStep;
    int     CanLeftRevStep;
    int     CanLeftFastRate;
    int     CanRightId;
    int     CanRightOrg;
    int     CanRightEncodeState;
    int     CanRightOff;
    int     CanRightRate;
    int     CanRightStep;
    int     CanRightSlowStep;
    int     CanRightRevStep;
    int     CanRightFastRate;
    int     CanForBackId;
    int     CanForBackEna;
    int     CanForBackOff;
    int     CanForBackMode;
    int     CanForBackRate;
    int     CanForBackFastRate;
    int     CanForBackStep;
    int     CanForBackSense1;
    int     CanForBackSense2;
    int     CanForBackResetRate;
    int     CanForBackResetStep;
    int     CanForBackLimitMin;
    int     CanForBackLimitMax;
    int     CanForBackSetIn;
    int     CanForBackSetOut;
    int     CanPushId;
    int     CanPushEna;
    int     CanPushOff;
    int     CanPushRate;
    int     CanPushLimit;
    int     CanPushMode;
    int     CanPushDown;
    int     CanPushUp;
    int     CanPushSense1;
    int     CanPushSense2;
    int     CanPushResetRate;
    int     CanPushResetStep;
}UI_UIM_VAR;

class Config
{
public:
    Config();
    ~Config();

    void setConfName(const QString name);
    void readConfig(void);

    QVariant getConfig(const char *set, const char *key);
    QVariant getConfVar(const char *key);
    QVariant getUiVar(const char *key);
    QVariant getSetupVar(const char *key);
    QVariant getShellVar(const char *key);
    QVariant getUimVar(const char *key);

    void saveConfig(void);
    void saveUim(void);

public:
    UI_CONF_VAR confVar;
    UI_UI_VAR uiVar;
    UI_SETUP_VAR setupVar;
    UI_SHELL_VAR shellVar;
    UI_UIM_VAR uimVar;

private:
    QSettings *configIni;
    QString confName;
};

#endif // CONFIG_H
